# 2.定义变量赋值不同的数据类型打印、并使用type
def use_ch_print():
    """
    定义变量赋值打印并打印其类型
    :return:
    """
    i = 1  # 整型
    j = 1.245  # 浮点数
    k = True  # bool
    a = False  # bool
    print(i)
    print(type(i))

    print(j)
    print(type(j))

    print(k)
    print(type(k))

    print(a)
    print(type(a))


use_ch_print()


# 3.将整型转为不同进制，进行输出
def use_transform():
    x = 112
    print(hex(x))  # 十六进制
    print(oct(x))  # 八进制
    print(bin(x))  # 二进制


use_transform()


# 4.从1到100之间的奇数求和

# 方法1
def odd_sum():
    i = 1
    count = 0
    while i < 100:
        if i % 2 == 0:
            i = i + 1
            pass
        count = count + i
        i = i + 1
    print(count)


odd_sum()

# 方法2
print(sum(i for i in range(1, 100) if i % 2 == 1))


# 5.九九乘法表
def chart_multiple():
    for i in range(1, 10):
        for j in range(1, i+1):
            print("%d * %d = %d" % (i, j, j*i), end='   |  ')
        print()
        print("-"*16*i)


chart_multiple()


# 6.一个整数对应的二进制数的1的个数
def num1_in_binary():
    x = int(input("输入一个整数："))
    y = bin(x)
    if x >= 0:
        num = y.count("1")
        print(y.count("1"))
    elif x < 0:
        x &= 0xFFFFFFFFFFFFFFFF
        print(bin(x).count("1"))


num1_in_binary()

def num1_in_binary1():
    x = int(input("输入一个整数："))
    y = bin(x)
    if x >= 0:
        num = y.count("1")
        print(y.count("1"))
    elif x < 0:
        num = 64-bin(-x-1)
        print(num)


num1_in_binary1()
